<?php
/**
 * Created by PhpStorm.
 * User: CY
 * Date: 2018/3/21
 * Time: 17:07
 */

namespace app\api\model;


class User extends BaseModel
{
    protected $autoWriteTimestamp = true;

    /**
     * 用户对应的订单
     * @return \think\model\relation\HasMany
     */
    public function orders(){
        return $this->hasMany('Order','user_id','id');
    }

    /**
     * 和用户收货地址表相关联
     * @return \think\model\relation\HasOne
     */
    public function address(){
        return $this->hasOne('UserAddress','user_id','id');
    }

    /**
     * 获取用户
     * @param $openid
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getByOpenID($openid){
        $user = self::where('openid','=',$openid)->find();
        return $user;
    }
}